package org.gap.jseed.utils;

import junit.framework.AssertionFailedError;

import org.junit.Assert;

public class AssertArrays {
	
	public static void arraysShareTheSame(Object[] expectedElements, Object[] actualElements) {
		Assert.assertEquals(toString(expectedElements), expectedElements.length, actualElements.length);
		for (Object eachFirst : expectedElements) {
			hasItem(eachFirst, actualElements);
		}
	}

	public static void hasItem(Object expected, Object[] actualElements) {
		for (Object eachSecond : actualElements) {
			if (expected.equals(eachSecond)) {
				return;
			}
		}
		throw new AssertionFailedError("[" + expected + "] was not contained in the list {" + toString(actualElements) + "}");
	}
	
    private static String toString(Object[] iteratedOver) {
        String result = "";
        for (Object each : iteratedOver) {
            result += "[" + each + "], ";
        }

        return result;
    }
}
